package com.hy.service.impl;

import com.hy.mapper.CityMapper;
import com.hy.mapper.DistrictMapper;
import com.hy.mapper.ProvinceMapper;
import com.hy.pojo.City;
import com.hy.pojo.Province;
import com.hy.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProvinceServiceImpl implements ProvinceService {
    @Autowired
    ProvinceMapper provinceDao;
    @Autowired
    CityMapper cityDao;
    @Autowired
    DistrictMapper districtDao;

    @Override
    public List<Province> findProvinces() {
        List< Province > list = provinceDao.findProvinces();
        return list;
    }

    @Override
    public List< Province > findProvince() {
        List< Province > list = provinceDao.findProvinces();
        for ( Province province : list ) {
            List<City> city = cityDao.findCity( province.getId() );
            for ( City city1 : city ) {
                city1.setDistricts( districtDao.findDistrict( city1.getId() ) );
            }
            province.setCities( city );
        }
        return list;
    }
}
